/*
 * @Author: szx
 * @Date: 2022-05-15 13:40:49
 * @LastEditTime: 2022-05-15 13:49:42
 * @Description:
 * @FilePath: \leetcode\面试题\03\02.js
 */

var MinStack = function () {
    this.stack = [];
    this.minStack = [];
};

/**
 * @param {number} x
 * @return {void}
 */
MinStack.prototype.push = function (x) {
    this.stack.push(x);
    const len = this.minStack.length;
    if (len == 0 || x <= this.minStack[len - 1]) this.minStack.push(x);
};

/**
 * @return {void}
 */
MinStack.prototype.pop = function () {
    const tmp = this.stack.pop();
    if (tmp === this.getMin()) {
        this.minStack.pop();
    }
};

/**
 * @return {number}
 */
MinStack.prototype.top = function () {
    return this.stack[this.stack.length - 1];
};

/**
 * @return {number}
 */
MinStack.prototype.getMin = function () {
    return this.minStack[this.minStack.length - 1];
};
